﻿using Heng.Elements.Core.Model.Infrastructure.Messages;
using Heng.Elements.Core.Model.Infrastructure.Repositories;
using Heng.Elements.Core.Model.Infrastructure.Services;
using Heng.Elements.ERD.Model.Entities;
using Heng.Elements.ERD.Model.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Heng.Elements.ERD.Model.Services
{
    public class DomainEntityRelationService : EntityServiceBase<DomainEntityRelation>
    {
        public DomainEntityRelationService(EntityRepositoryContext ctx)
            :base(ctx)
        {
        }

        public ServiceResponse<IEnumerable<DomainEntityRelation>> GetByEntity(long entityId)
        {
            var response = ExecInContext<IEnumerable<DomainEntityRelation>>((ctx, res) =>
                {
                    var repo = ctx.GetRepository<IDomainEntityRelationRepository>();
                    var relations = repo.GetByEntity(entityId);
                    return relations;
                });

            return response;
        }
    }
}
